﻿using Microsoft.EntityFrameworkCore;

namespace EfTest
{
    internal class Program
    {
        static void Main(string[] args)
        {
            using var context = new BloggingContext();
            var blog = new Blog { Name = "My First Blog" };
            blog.Posts.Add(new Post { Title = "First Post", Content = "This is the content of the first post." });
            context.Blogs.Add(blog);
            context.SaveChanges();

            //var blog = context.Blogs.First();
            context.Entry(blog).Collection(b => b.Posts).Load();
            
            blog.Posts.Add(new Post { Title = "Second Post", Content = "This is the content of the second post." });
            blog.Posts.Add(new Post { Title = "Thrid Post", Content = "This is the content of the third post." });
            context.SaveChanges();
           
            context.Remove(blog.Posts.First());
            context.SaveChanges();

            if (blog != null)
            {
                Console.WriteLine($"Blog found: {blog.Name}");
            }
        }
    }
}
